﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class EditCategory : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Label10.Visible = false;
            

            Button2.Attributes.Add("onclick","confirm('Are you sure you want to proceed?')");
            LoadData();
          
        }
      
      
    
      
    }

    private void LoadData()
    {
        string id = Request.QueryString["id"].ToString();
        ManagementPaymentDetail m = new ManagementPaymentDetail();
        ORANGE_PROJECTModel.PaymentMethodDetail s = (ORANGE_PROJECTModel.PaymentMethodDetail)m.GetEditPaymentDetail(id);
       
        DropDownList1.DataSource = m.GetPaymentMethod();
        DropDownList1.DataBind();
        DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue(s.PaymentMethodID + ""));

        txtID.Text = (id).ToString();
        txtName.Text = s.DetailName;
        txtNote.Text = s.Note;
        txtCharges.Text = s.PriceCharges.ToString();
    }

    
    protected void Button1_Click(object sender, EventArgs e)
    {

        ManagementPaymentDetail m = new ManagementPaymentDetail();
        
        if (m.UpdatePaymentDetail(txtID.Text,txtName.Text,Double.Parse(txtCharges.Text),txtNote.Text,Int32.Parse(DropDownList1.SelectedValue)))
        {
           
            LoadData();
            Label10.Visible = true;
            Label10.Text = "<span style='color:green;font-weight: bold;'>Update Succerfully :)</span>";
            
        }
        else {
            Label10.Visible = true;
            Label10.Text = "<span style='color:red;font-weight: bold;'>Update Failed (:</span>";
        }
        
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        string id = Request.QueryString["id"].ToString();
        ManagementPaymentDetail m = new ManagementPaymentDetail();
        if (m.DeletePaymentDetail(id))
        {
            Response.Redirect("ManagementPaymentDetail.aspx");
        }
    }
}